
package com.itheima.health.controller;

import com.itheima.health.dto.RoleDto;
import com.itheima.health.entity.QueryPageBean;
import com.itheima.health.entity.Result;
import com.itheima.health.service.RoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;

@RestController
@Api(tags = "角色模块管理")
@RequestMapping("role")
public class RoleController {

    @Reference
    private RoleService roleService;

    @GetMapping("findAll")
    @ApiOperation(value = "查询所有",notes = "查询所有角色列表信息")
    public Result findAll(){
        return new Result(roleService.list());
    }

    @PostMapping("findpage")
    @ApiOperation(value = "分页查询",notes = "分页查询角色列表信息")
    public Result findPage(@RequestBody QueryPageBean queryPageBean){
        return new Result(roleService.findPage(queryPageBean));
    }

    @PostMapping("saveOrUpdate")
    @ApiOperation(value = "新增或更新角色信息",notes = "未携带id时新增，携带id时更新角色信息")
    public Result saveOrUpdate(@RequestBody RoleDto roleDto){
        return new Result(roleService.saveUpdate(roleDto));
    }

    @GetMapping("findPidByRid/{rid}")
    @ApiOperation(value = "根据角色id查询权限id",notes = "根据传来的角色id查询权限ids,查询角色信息，查询所有权限信息菜单信息，用于回显数据")
    public Result findPidByRid(@PathVariable("rid") Integer rid){
        return new Result(roleService.findPidByRid(rid));
    }

    @DeleteMapping("deleteById/{id}")
    @ApiOperation(value = "删除角色",notes = "根据id删除角色")
    public Result deleteById(@PathVariable("id") Integer id){
        return new Result(roleService.deleteById(id));
    }
}
